﻿from threading import Lock


class SimpleSyncDict:
  def __init__(self):
    self.lock = Lock()
    self.lock.acquire()
    self.dict = {}
    self.lock.release()

  def __len__(self):
    self.lock.acquire()
    length = len(self.dict)
    self.lock.release()
    return length

  def __setitem__(self, key, val):
    self.lock.acquire()
    self.dict[key] = val
    self.lock.release()

  def __getitem__(self, key):
    self.lock.acquire()
    val = self.dict[key]
    self.lock.release()
    return val

  def __delitem__(self, key):
    self.lock.acquire()
    del self.dict[key]
    self.lock.release()

  def has_key(self, key):
    self.lock.acquire()
    res = self.dict.has_key(key)
    self.lock.release()
    return res

  def __contains__(self, key):
    return self.has_key(key)
